package com.bleeth.fx.component;

import com.bleeth.fx.helper.StyleHelper;
import com.bleeth.fx.helper.ThemeTypeEnum;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.Circle;
import lombok.Builder;


/**
 * @author Sakura
 * @version 1.0
 * @date 2021-11-13 22:17
 **/
@Builder
public class MProgress {

    @Builder.Default
    private double size = 100;


    @Builder.Default
    private String color = "#cae6ca";

    private static final String DEFAULT_COLOR = "#d6d6d6";

    public Region make() {
        StackPane box = new StackPane();
        Circle outer = new Circle();
        Circle inner = new Circle();
        Arc arc = new Arc();
        arc.setTranslateX(25);
        arc.setTranslateY(-25);
        arc.setRadiusX(size / 2);
        arc.setRadiusY(size / 2);
//        arc.setStartAngle(90);  // 定义弧的起始角度
        arc.setLength(60);  // 弧的角度范围
        arc.setType(ArcType.ROUND);

        //设置大小
        box.setPrefSize(size, size);
        outer.setRadius(size / 2);
        inner.setRadius((size - 10) / 2);


        //样式
//        StyleHelper.bg(box).color(ThemeHelper.PRIMARY_BG_COLOR).make();
//        StyleHelper.br(box).color(ThemeHelper.PRIMARY_BG_COLOR).width(1).make();
        outer.setFill(Paint.valueOf(DEFAULT_COLOR));
        inner.setFill(Paint.valueOf(ThemeTypeEnum.WHITE_COLOR.getValue()));


//        box.getChildren().addAll(outer, arcBox(size, color), inner);
        box.getChildren().add(arcBox(size,color));
        return box;
    }


    private Region arcBox(double size, String color) {
        Arc arc = new Arc();

        arc.setRadiusX(size / 2);
        arc.setRadiusY(size / 2);
        arc.setLength(90);  // 弧的角度范围
        arc.setType(ArcType.ROUND);
        HBox box = new HBox();
        box.setPrefSize(size, size);
        box.setFillHeight(false);
        box.getChildren().add(arc);

        arc.setCenterY(0);
        arc.setLayoutX(25);
//        arc.centerYProperty().bind(box.prefHeightProperty().divide(2));

        arc.setFill(Paint.valueOf(color));
        StyleHelper.bg(box).color(ThemeTypeEnum.PRIMARY_COLOR.getValue()).make();
        return box;
    }


}
